<?php
/**注意此文档为UTF-8的编码.
 * Created on 2010-6-27
 *
 * @author EXT <isrn@qq.com>
 *
 */
include ('../../includes/global.php');
include ('../global.php');
include ("../power.php");
//require_once './render.php';
//require_once './items_config.php';
$dbcfg=Sys::Gp(array('dbcfg','sevenel'));
$donotrender = array('htmleditor','fckeditor','password','hidden');

 switch($_REQUEST['op']){
	case 'list':{
			$fldata=Dgd(array(
			  'db'=>'d_sevenel',
			  'cd'=>"tid = '".$_GET['tid']."' order by px asc ",
			  'tn'=>"fld"
			));
		Tr($fldata,'fld');
		Tr($_GET['bdtid'],'bdtid');
		Tr($_GET['bdid'],'bdid');
		foreach($fldata as $key =>$v){
				if($v['xr']==0){
					$xr[]=$v;
					}
				if($v['gj']==1){
					$gj[]=$v;
					}
			}
		Tr($xr,'xr');
		if($gj!=''){
		foreach($gj as $key =>$value){
			if($value['cfg']!=''){
			$config =json_decode($value['cfg'],true);
			}else{$config =''; }
			$config['STR']=str_replace("\r","",$config['STR']);
			$config['STR']=str_replace("\n","",$config['STR']);
			$config['STR']=str_replace("\t","",$config['STR']);
			switch($value['type']){
				case 'datefield':{
						$js[] ="{
							xtype: 'datefield',
							value:\"\",
							fieldLabel:'".$value['name']."',
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							".(($config['STR'])?("".$config['STR'].""):(""))."
							".(($config['zqgs'])?("format:'".$config['zqgs']."',"):(""))."
							name: '".$value['fname']."'
							}";
							break;}
				case 'combo':{
								$tempxx = json_decode($value['zyz'],true);
								$config_num = count($tempxx);
								$items='';
								if($config_num != 0){
									foreach($tempxx as $key => $data){
										if($data['ck']=='1'){
											$xzz=$data['xv'];}
											$items.= "['".$data['xv']."','".$data['yv']."']";
										if($key < $config_num-1){
											$items.= ",";
										}
									}
								}
						$js[] ="{
							value:\"".$xzz."\",
							fieldLabel:'".$value['name']."',
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							".(($value['width'])?("width:".$value['width'].","):(""))."
							".(($config['readonly'])?("readOnly:'true',"):(""))."
							typeAhead: true,
							name: '".$value['fname']."_',
							hiddenName : '".$value['fname']."',
							editable: false,xtype: 'combo',
							store:new Ext.data.SimpleStore({
											fields:['name','value'],
											data:[".$items."]}),
							mode:'local',
					        displayField:'name',
					        selectOnFocus:true,
					        valueField :'value',
					        triggerAction:'all'

							}";
				break;}
				case 'radiogroup':{
								$tempxx = json_decode($value['zyz'],true);
								$config_num = count($tempxx);
								if($config_num != 0){
									$items='';
									foreach($tempxx as $key => $data){
										if($data['ck']=='1'){
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."',inputValue:'".$data['yv']."',checked: true}";}else{
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."',inputValue:'".$data['yv']."'}";}
										if($key < $config_num-1){
											$items.= ",";
										}
									}
								}
						$js[] ="{
							xtype: 'radiogroup',
							".(($value['width']&&$value['width']<=$config_num)?("columns:".$value['width'].","):(""))."
							".(($config['vertical'])?("vertical: true,"):(""))."
							anchor: '95%',
							 items: [".$items."],
							fieldLabel:'".$value['name']."'
							}";
				break;}
				case 'recommend':{
							$items='';
								$items.= "{boxLabel:'推荐中',name:'".$value['fname']."',inputValue:'1'},";
								$items.= "{boxLabel:'不推荐',name:'".$value['fname']."',inputValue:'0',checked: true}";
								
						$js[] ="{
							xtype: 'radiogroup',
							anchor: '95%',
							 items: [".$items."],
							fieldLabel:'".$value['name']."'
							}";
				break;}
				case 'checkboxgroup':{
								$tempxx = json_decode($value['zyz'],true);
								$config_num = count($tempxx);
								if($config_num != 0){
									$items='';
									foreach($tempxx as $key => $data){
									$ckbox[]=$value['fname']."[".$key."]";	
										if($data['ck']=='1'){
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."[".$key."]',inputValue:'".$data['yv']."',checked: true}";}else{
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."[".$key."]',inputValue:'".$data['yv']."'}";}
										if($key < $config_num-1){
											$items.= ",";
										}
										}
								}
						$js[] ="{
							xtype:'checkboxgroup',
							".(($value['width']&&$value['width']<=$config_num)?("columns:".$value['width'].","):(""))."
							".(($config['vertical'])?("vertical: true,"):(""))."
							anchor: '95%',
							 items: [".$items."],
							fieldLabel:'".$value['name']."'
							}";
				break;}
				default:{
						$js[] ="{
							xtype: 'textfield',
							value:\"\",
							fieldLabel:'".$value['name']."',
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							".(($value['width'])?("width:'".$value['width']."px',"):("grow:true,growMin:68,growMax:300,"))."
							".(($config['STR'])?("".$config['STR'].""):(""))."
							name: '".$value['fname']."'
							}";
						}
		  }
		}
		}
		Tr($ckbox,'ckbox');
		Tr($js,'js');
		$tree=Dgd(array(
			  'db'=>'d_sevenel',
			  'cd'=>"id = '".$_GET['tid']."' ",
			  'tn'=>"tree",
			  'limit'=>1
			));
		Tr($tree,'tree');
		if($tree['expand']){
		$fstree=Dgd(array(
			  'db'=>'d_sevenel',
			  'cd'=>"id in (0,".$tree['expand'].") ",
			  'tn'=>"tree"
			));}
		$fsstr='';
		if($fstree){
		foreach($fstree as $fsvalue){
		$fsstr.=",{xtype:\"button\",text:\"添加".$fsvalue['title']."\",iconCls:\"fsadd\",pressed:true,handler:function(){
				var record = grid.getStore().getAt(rowIndex); 
				fsadd('".$fsvalue['id']."','".$fsvalue['title']."',\"./show1/i.php?op=add&tid=".$fsvalue['id']."&bdtid=".$_GET['tid']."&bdid=\",record.data.id);		}}
				,{xtype:\"button\",text:\"浏览".$fsvalue['title']."\",iconCls:\"fslist\",pressed:true,handler:function(){
				var record = grid.getStore().getAt(rowIndex); 
				fslist('".$fsvalue['id']."','".$fsvalue['title']."',\"./show1/l.php?op=list&tid=".$fsvalue['id']."&bdtid=".$_GET['tid']."&bdid=\",record.data.id);
					}}";				
			}}
		Tr($fsstr,'fstree');
		
		$table=Dgd(array(
			  'db'=>'d_sevenel',
			  'cd'=>"id = '".$tree['table']."' ",
			  'tn'=>"datamod",
			  'limit'=>1
			));
		Tr($table,'table');
		
		Ts('right/list.html');
		break;
		}
	case 'fy':{
		
			$fldata=Dgd(array(
			  'db'=>'d_sevenel',
			  'cd'=>"tid = '".$_POST['tid']."' order by px asc ",
			  'tn'=>"fld"
			));
			$zhuanyi=array();
			$btsc=array();
			$gjsc=array();
			foreach($fldata as $key=>$value){
					if($value['zy']==1){
						$zhuanyi[]=$value;
						}
					if($value['bt']==1){
						$btsc[$value['fname']]=$value['type'];
						}
					if($value['gj']==1){
						$gjsc[]=$value;
						}
				}
			$condition='';
			$_POST['user']&&$condition.="and user like '%".$_POST['user']."%' ";
			$_POST['bdtid']&&$condition.="and bdtid = '".$_POST['bdtid']."' ";
			$_POST['bdid']&&$condition.="and bdid = '".$_POST['bdid']."' ";
			 if($gjsc){
				 $xzt=array('combo','recommend','radiogroup');
				foreach($gjsc as $value){
					if(in_array($value['type'],$xzt)){
					$_POST[$value['fname']]!=''&&$condition.="and ".$value['fname']." = '".$_POST[$value['fname']]."' ";
						}else{
							if($value['type']=='checkboxgroup'){
								if($_POST[$value['fname']]){
								 foreach($_POST[$value['fname']] as $cv){
					$cv!=''&&$condition.="and ".$value['fname']." like '%".$cv."%' ";
									 }
									}
								}else{
					$_POST[$value['fname']]!=''&&$condition.="and ".$value['fname']." like '%".$_POST[$value['fname']]."%' ";
									}
							}
					} 
				 }
			$dbinfo=Dgd(array(
					  'db'=>'d_sevenel',
					  'tn'=>$_POST['dbname'],
					  'start'=>$_POST['start'],
					  'limit'=>$_POST['limit'],
					  'total'=>true,
					 // 'ce'=>1,
					  'cd'=>" 1 and tid = '".$_POST['tid']."' ".$condition." and del != '1' order by id desc "
					  ));
			//统计
			
			
			//转换
			
		foreach($dbinfo['data'] as $key =>$value){
						foreach($zhuanyi as $zyv){
								switch($zyv['type']){
									case 'fileup':{
										//echo $dbinfo['data'][$key][$zyv['fname']];
										$config=json_decode($zyv['cfg'],true);
										$dvalue=array( 0=>array('rar','zip','tar','.tz'),
													   1=>array('jpg','gif','png','bmp'),
													   2=>array('mp3','mp4','avi','wmv','mid','.rm','mvb','mov','wma','wav'),
													   3=>array('doc','xls','txt','ocx','lsx','ppt','pdf','chm'),
													   4=>array('doc','xls','txt','ocx','lsx','ppt','pdf','chm','mp3','mp4','avi','wmv','mid','.rm','mvb','mov','wma','wav','jpg','gif','png','bmp','rar','zip','tar','.tz')		   
															   );
										$otype=substr(strtolower($dbinfo['data'][$key][$zyv['fname']]),-3);
												if(in_array($otype,$dvalue[0])){
												$dbinfo['data'][$key][$zyv['fname']]="<a href=\"/uplods/pic/".$dbinfo['data'][$key][$zyv['fname']]."\" target='_blank'><img src=\"../img/archive.png\">下载[Download]</a>";
													}
												if(in_array($otype,$dvalue[1])){
													if($config['sl1']==1){
													$dbinfo['data'][$key][$zyv['fname']]="<img src=\"/uplods/thumb1/".$dbinfo['data'][$key][$zyv['fname']]."\" >";	
														}elseif($config['sl2']==1){
													$dbinfo['data'][$key][$zyv['fname']]="<img src=\"/uplods/thumb2/".$dbinfo['data'][$key][$zyv['fname']]."\" >";	
															}elseif($config['sypic']==1||$config['sytxt']==1){
													$dbinfo['data'][$key][$zyv['fname']]="<img src=\"/uplods/sytp/".$dbinfo['data'][$key][$zyv['fname']]."\"  width=\"100px\">";	
															}else{
													$dbinfo['data'][$key][$zyv['fname']]="<img src=\"/uplods/pic/".$dbinfo['data'][$key][$zyv['fname']]."\"  width=\"100px\">";	
																}
													}
												if(in_array($otype,$dvalue[2])){
												$dbinfo['data'][$key][$zyv['fname']]="<a href=\"/uplods/pic/".$dbinfo['data'][$key][$zyv['fname']]."\" target='_blank'><img src=\"../img/film_link.png\">下载[Download]</a>";
													}
												if(in_array($otype,$dvalue[3])){
												$dbinfo['data'][$key][$zyv['fname']]="<a href=\"/uplods/pic/".$dbinfo['data'][$key][$zyv['fname']]."\" target='_blank'><img src=\"../img/report_word.png\">下载[Download]</a>";
													}
										break;	
										}
									case 'radiogroup':{	
									$tempxx = json_decode($zyv['zyz'],true);
									foreach($tempxx as $value){
											if($value['yv']==$dbinfo['data'][$key][$zyv['fname']]){
											$dbinfo['data'][$key][$zyv['fname']]=$value['xv'];
												}
										}
										break;
										}
									case 'checkboxgroup':{	
									$tempxx = json_decode($zyv['zyz'],true);
									$nowv=explode('#_#',$dbinfo['data'][$key][$zyv['fname']]);
									$dbinfo['data'][$key][$zyv['fname']]='';
									foreach($tempxx as $value){
											if(in_array($value['yv'],$nowv)){
											$dbinfo['data'][$key][$zyv['fname']].=$value['xv']."<BR>";
												}
										}
										break;
										}
									case 'combo':{	
									$tempxx = json_decode($zyv['zyz'],true);
									foreach($tempxx as $value){
											if($value['yv']==$dbinfo['data'][$key][$zyv['fname']]){
											$dbinfo['data'][$key][$zyv['fname']]=$value['xv'];
												}
										}
										break;
										}
									case 'recommend':{	
										$config=json_decode($zyv['cfg'],true);
										if($dbinfo['data'][$key][$zyv['fname']]!=0){
											$dbinfo['data'][$key][$zyv['fname']]="<a href=\"#\" onclick='gxzd(\"".$dbinfo['data'][$key]['id']."\",\"".$zyv['fname']."\",\"0\")' title=\"推荐中！单击取消推荐\"  >  <img src=\"../img/".$config['paixu']."\"></a>    <a href=\"#\"  title=\"排序[order]\"  onclick='tjpx(\"".$_POST['tid']."@".$_POST['dbname']."\",\"".$zyv['fname']."\")' >   <img src=\"../img/sucaiwcom8170000bzc.gif\" ait=\"排序[order]\"></a>";
												}else{
											$dbinfo['data'][$key][$zyv['fname']]="<a href=\"#\" onclick='gxzd(\"".$dbinfo['data'][$key]['id']."\",\"".$zyv['fname']."\",\"1\")'  title=\"未推荐！单击推荐\"  ><img src=\"../img/flag.png\"></a> <a href=\"#\" title=\"排序[order]\"   onclick='tjpx(\"".$_POST['tid']."@".$_POST['dbname']."\",\"".$zyv['fname']."\")' >  <img src=\"../img/sucaiwcom8170000bzc.gif\" ait=\"排序[order]\"></a>";
													}
										break;
										}
									}
							
							}
						
				}
/*				
			$_SESSION['as']=$_SESSION['as']+10;
			$dbinfo['as']=$_SESSION['as'];
*/			echo json_encode($dbinfo);
			break;
		}
	case 'width_change':{
	$id=$_POST['id'];
	Du('sevenel','fld',array('wd'=>$_POST['width']),'id',$id,1);
	echo 'ok';
	break;
	}
	case 'del':{
	$_POST['del']=1;
	$_POST['ids']=json_decode(stripslashes($_POST['ids']));
	if(is_array($_POST['ids'])){
		foreach($_POST['ids'] as $id){
			Du('sevenel',$_POST['dbname'],$_POST,'id',$id,0);
			}				   
		}else{
			Du('sevenel',$_POST['dbname'],$_POST,'id',$id,0);
			}
	 echo '{success:true,msg:\'ok\'}';
	break;
	}

 }
?>